package com.ewhale.feitengguest.ui.shop.mine

import android.os.Bundle
import android.view.View
import com.ewhale.feitengguest.R
import com.ewhale.feitengguest.dto.ShopBillDetailDto
import com.ewhale.feitengguest.dto.ShopBillDto
import com.ewhale.feitengguest.dto.ShopWalletDto
import com.ewhale.feitengguest.presenter.shop.mine.ShopWalletPresenter
import com.ewhale.feitengguest.view.shop.mine.ShopWalletView
import com.simga.library.activity.MBaseActivity
import kotlinx.android.synthetic.main.activity_shop_bill_detail.*

class ShopBillDetailActivity : MBaseActivity<ShopWalletPresenter>(), ShopWalletView {
    override fun showWallet(shopWalletDto: ShopWalletDto) {}
    override fun showShopBillList(list: List<ShopBillDto>) {}
    override fun getViewId(): Int {
        return R.layout.activity_shop_bill_detail
    }

    override fun isUseBaseTitleBar(): Boolean {
        return true
    }
    private var billId: Int? = null
    override fun onGetBundle(bundle: Bundle?) {
        super.onGetBundle(bundle)
        billId = bundle!!.getInt("billId")
    }

    override fun init(savedInstanceState: Bundle?) {
        setTitle("账单详情")
        presenter.getShopBillDetail(billId)
    }

    override fun showShopBillDetail(detatil: ShopBillDetailDto) {
        tv_creat_time.text = detatil.createTime
        tv_orderNum.text = detatil.orderSn
        tv_amount.text = detatil.amount.stripTrailingZeros().toPlainString()
        tv_orderNumHint.text = if (detatil.type == 2 || detatil.type == 4 || detatil.type == 6) "流水号" else "订单号"
        when (detatil.type) {
            1 -> {
                tv_shopName.text = "余额充值"
                tv_payType.text = when (detatil.payType) {
                    1 -> "微信"
                    2 -> "支付宝"
                    else -> "余额"
                }
                tv_bill_type.text = "充值收入"
            }
            2 -> {
                cl_shopHint.visibility = View.GONE
                tv_payType.text = when (detatil.withdrawalType) {
                    1 -> "微信"
                    else -> "支付宝"
                }
                tv_payTypeHint.text = "提现账户"
                tv_bill_type.text = "提现支付"
                when (detatil.withdrawalStatus) {
                    0 -> {
                        tv_bill_status.text = "正在处理中"
                        tv_bill_status.visibility = View.VISIBLE
                    }
                    2 -> {
                        tv_bill_status.visibility = View.VISIBLE
                        tv_remark.text = detatil.refuseCause
                        cl_task.visibility = View.VISIBLE
                        tv_remark.text = detatil.refuseCause
                        tv_bill_status.text = "提现失败"
                    }
                }
            }
            3 -> {
                tv_shopName.text = detatil.missionTitle
                tv_payType.text = when (detatil.payType) {
                    1 -> "微信"
                    2 -> "支付宝"
                    else -> "余额"
                }
                tv_bill_type.text = "任务发布"
                cl_viewTaks.visibility = View.VISIBLE
                tv_shop_hint.text = "任务说明"
            }
            4, 6 -> {
                cl_shopHint.visibility = View.GONE
                tv_payType.text = when (detatil.withdrawalType) {
                    1 -> "微信"
                    else -> "支付宝"
                }
                tv_remark.text = detatil.refuseCause
                cl_task.visibility = View.VISIBLE
                tv_remark.text = detatil.refuseCause
                tv_bill_type.text = "提现失败"
            }
            5 -> {
                tv_shopName.text = detatil.missionTitle
                tv_payType.text = when (detatil.payType) {
                    1 -> "微信"
                    2 -> "支付宝"
                    else -> "余额"
                }
                cl_viewTaks.visibility = View.VISIBLE
                tv_bill_type.text = "任务更改"
                tv_shop_hint.text = "任务说明"
            }
        }
    }

    override fun initListener() {
        super.initListener()
        cl_viewTaks.setOnClickListener {

        }
    }

    override fun showProLoading() {
        showLoading()
    }

    override fun dimissProLoading() {
        dismissLoading()
    }

    override fun showErrorMessage(postCode: Int, code: String?, message: String?) {
        showErrorMsg(code, message)
    }

    companion object {
        fun open(mContext: MBaseActivity<*>, billId: Int) {
            val bundle = Bundle()
            bundle.putInt("billId", billId)
            mContext.startActivity(bundle, ShopBillDetailActivity::class.java)
        }
    }
}
